<?php
/**
 * Created by PhpStorm.
 * User: aijing
 * Date: 2018/4/10
 * Time: 16:59
 */
header("content-Type:text/html;charset=utf-8");
$con = mysqli_connect("127.0.0.1","root","123456");
mysqli_select_db($con,"my_db");

var_dump($_FILES);

$filename ="/Users/tu/Desktop";
move_uploaded_file($_FILES["file"]["tmp_name"],$filename);//将临时地址移动到指定地址
die();



switch($_GET["action"]){
    case "add":
        $name = $_POST["name"];
        $typeid = $_POST["typeid"];
        $price = $_POST["price"];
        $total = $_POST["total"];
        $note = $_POST["note"];
        $addtime = time();
        //2.验证()省略
        if(empty($name))
        {
            die("商品名称必须有值");
        }
        //5.拼装sql语句，并执行添加
        $sql = "insert into goods values(null,'{$name}','{$typeid}',{$price},{$total},'{$note}',{$addtime})";
        mysqli_query($con,$sql);
        //6.判断并输出结果
        if(mysqli_insert_id($con)>0)
        {
            echo "商品发布成功";
        }else
        {
            echo "商品发布失败";
        }
        echo "<br> <a href='self.php'>查看商品信息<a>";

        break;
    case "del": //删除
        //获取要删除的id号并拼装删除sql，执行
        $sql2 = "delete from goods where id={$_GET['id']}";
        mysqli_query($con,$sql2);
        //跳转到浏览界面
        header("Location:self.php");
        break;
    case "update":  //修改
        //1.获取要修改的信息
        $name = $_POST["name"];
        $typeid = $_POST["typeid"];
        $price = $_POST["price"];
        $total = $_POST["total"];
        $note = $_POST["note"];
        $id = $_POST['id'];
        //2.数据验证
        if(empty($name))
        {
            die("商品名称必须有值");
        }
        //5.执行修改
        $sql = "update goods set name='{$name}',typeid={$typeid},total={$total},note='{$note}',price={$price} where id={$id}";
        mysqli_query($con,$sql);
        //6.判断是否修改成功
      echo "<br> <a href='self.php'>查看商品信息<a>";
        break;
    default:
        echo "错误";break;
}?>
<html>
<head>
    <style type="text/css">
        html,body{
            padding:0;
            margin:0;
            background-color:#201612;
            height:100%;
            width:100%;
            color:#7e725e;
            font-size: 20px;
        }
</head>
<body>
</body>
</html>